' This script will display a directory list dialog, open the folder selected,
' update the document info of the file and save it into a new file and then
' create a thumbnail of the file and save it as a separate jpeg file.

Private Sub Command1_Click()

Dim appRef As Photoshop.Application
Dim docRef As Photoshop.Document
Dim dupDocRef1 As Photoshop.Document
Dim dupDocRef2 As Photoshop.Document
Dim docInfoRef As Photoshop.DocumentInfo
Dim fsoRef As Scripting.FileSystemObject
Dim folderRef As Scripting.Folder
Dim convertedFolderRef As Scripting.Folder
Dim fileCollection As Scripting.Files
Dim fileRef As Scripting.File
Dim extType As Photoshop.PsExtensionType
Dim newFileName1 As String
Dim newFileName2 As String
Dim newFolderName As String
Dim saveOptionsRef As Photoshop.PsSaveOptions
Dim i As Long
Dim theFolderPath As String

theFolderPath = Dir1.Path

Set appRef = New Photoshop.Application
appRef.DisplayDialogs = psDisplayNoDialogs

i = 0
Set fsoRef = New Scripting.FileSystemObject
Set folderRef = fsoRef.GetFolder(theFolderPath)
newFolderName = theFolderPath & "\Converted"
saveOptionsRef = psDoNotSaveChanges

If fsoRef.FolderExists(newFolderName) Then
    Set convertedFolderRef = fsoRef.GetFolder(newFolderName)
Else
    Set convertedFolderRef = fsoRef.CreateFolder(newFolderName)
End If

Set fileCollection = folderRef.Files
extType = psLowercase

Dim strtRulerUnits As PsUnits
strtRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = psInches
  
For Each fileRef In fileCollection

  Label2.Caption = "Working..."

    On Error Resume Next

    ' open the file and make first duplicate.
    Set docRef = appRef.Open(fileRef.Path)
    Set dupDocRef1 = docRef.Duplicate
    
    ' Update the document info of the file.
    Set docInfoRef = dupDocRef1.Info
    docInfoRef.Copyrighted = psCopyrightedWork
    docInfoRef.CopyrightNotice = "Copyright 2002, Cool Photoshop Stuff"
    
    ' Create the JPEG options and set the options.
    Dim jpgSaveOptions As Photoshop.JPEGSaveOptions
    Set jpgSaveOptions = New Photoshop.JPEGSaveOptions
    jpgSaveOptions.EmbedColorProfile = True
    jpgSaveOptions.FormatOptions = psStandardBaseline
    jpgSaveOptions.Matte = psNoMatte
    jpgSaveOptions.Quality = 1
    
    ' Make up a new name for the new file.
    newFileName1 = convertedFolderRef.Path & "\Temp00" & i
    newFileName1 = newFileName1 & ".jpg"
    
    ' Save with new document information and close the file.
    dupDocRef1.SaveAs newFileName1, Options:=jpgSaveOptions, AsCopy:=True, extensionType:=extType
    dupDocRef1.Close Saving:=saveOptionsRef
    
    ' Now create a 1x1 inch thumbnail with a second duplication.
    Set dupDocRef2 = docRef.Duplicate
    dupDocRef2.ResizeImage Width:=1, Height:=1
    
    ' Make up a new name for new thumbnail file.
    newFileName2 = convertedFolderRef.Path & "\Thumbnail00" & i
    newFileName2 = newFileName2 + ".jpg"
    
    ' Save with new document info and close the file.
    dupDocRef2.SaveAs newFileName2, Options:=jpgSaveOptions, AsCopy:=True, extensionType:=extType
    dupDocRef2.Close Saving:=saveOptionsRef
    
    docRef.Close Saving:=saveOptionsRef
                     
    i = i + 1

Next

appRef.Preferences.RulerUnits = strtRulerUnits
Label2.Caption = "Conversion completed"
    
End Sub
